package com.black.utils.file.compress.jar.entity;

import lombok.Getter;
import lombok.Setter;
import org.objectweb.asm.Opcodes;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ylx
 */
@Getter
@Setter
public class JavaInfo implements Opcodes {
    protected int access;
    protected String name;
    protected String desc;
    protected String signature;
    protected final Map<String, AnnotationInfo> annotations = new HashMap<>();

    public JavaInfo(String name) {
        this(Opcodes.ACC_PUBLIC, name);
    }

    public JavaInfo(int access, String name) {
        this.access = access;
        this.name = name;
    }

    public void addAnnotation(String name, AnnotationInfo annotationInfo) {
        this.annotations.put(name, annotationInfo);
    }

    public boolean hasAnnotation(String name) {
        return annotations.values().stream().anyMatch(annotationInfo -> annotationInfo.getName().contains(name));
    }

    public AnnotationInfo getAnnotation(String name) {
        return annotations.values().stream().filter(annotationInfo -> annotationInfo.getName().contains(name)).findFirst().orElse(null);
    }
}
